package com.tegtech.module.auth.service.impl;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tegtech.module.auth.domain.SysMenu;
import com.tegtech.module.auth.mapper.UserMenuPermsMapper;
import com.tegtech.module.auth.service.IUserMenuPermsService;

import cn.hutool.core.lang.Validator;

/**
 * 菜单 业务层处理
 *
 * @author Jun
 */
@Service
public class UserMenuPermsServiceImpl extends ServiceImpl<UserMenuPermsMapper, SysMenu> implements IUserMenuPermsService {

    /**
     * 根据用户ID查询权限
     *
     * @param userId 用户ID
     * @return 权限列表
     */
    @Override
    public Set<String> selectMenuPermsByUserId(Long userId) {
        List<String> perms = baseMapper.selectMenuPermsByUserId(userId);
        Set<String> permsSet = new HashSet<>();
        for (String perm : perms) {
            if (Validator.isNotEmpty(perm)) {
                permsSet.addAll(Arrays.asList(perm.trim().split(",")));
            }
        }
        return permsSet;
    }

}
